package com.example.anew.journey.mynewjourney.firstchangelogic.FirstChangeMain.adpater;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;

import com.bumptech.glide.Glide;
import com.example.anew.journey.mynewjourney.R;
import com.example.anew.journey.mynewjourney.config.RBConstants;
import com.example.anew.journey.mynewjourney.firstchangelogic.FirstChangeMain.bean.MainListBean;
import com.example.anew.journey.mynewjourney.inteface.OnRecyclerViewItemClickListener;

import java.util.ArrayList;
import java.util.List;


/**
 * 杭州惟君医疗科技有限公司14
 * Created by 20433 on 2018/3/14
 */

public class MyMainDevicesHotAdapter extends  RecyclerView.Adapter<MyMainDevicesHotAdapter.ViewHolder> implements View.OnClickListener{
    private OnRecyclerViewItemClickListener mOnItemClickListener = null;
    private List<MainListBean.DataBean> mList = new ArrayList<>();

    private Context mcontxt;
    public MyMainDevicesHotAdapter(Context contxt) {
        mcontxt = contxt;
    }

    public void setOnItemClickListener(OnRecyclerViewItemClickListener listener) {
        this.mOnItemClickListener = listener;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mcontxt).inflate(R.layout.my_main_devics_item,parent,false);
        // 实例化viewholder
        ViewHolder viewHolder = new ViewHolder(view);
        view.setOnClickListener(this);
        return viewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
       Glide.with(mcontxt).load(RBConstants.SERVER_URL +"/Public/Uploads/"+mList.get(position).url).into(holder.iv_devices_pictru);
       // NLogger.e("TAG","main====3==========="+RBConstants.SERVER_URL +"/Public/Uploads/"+mList.get(position).url);
    }

    public void AddItem(List<MainListBean.DataBean> beanList){
        mList.addAll(beanList);
        notifyDataSetChanged();
      //  NLogger.e("TAG","main==2============="+mList.size());
    }
    public void  clearItem(){
        mList.clear();
        notifyDataSetChanged();
    }
    @Override
    public int getItemCount() {
       // NLogger.e("TAG","main==4============="+mList.size());
        return mList.size();
    }

    @Override
    public void onClick(View view) {
        if(mOnItemClickListener != null ){
            mOnItemClickListener.onItemClick(view);
        }
    }

    public static class ViewHolder extends RecyclerView.ViewHolder {
        private  ImageView iv_devices_pictru;
        public ViewHolder(View itemView) {
            super(itemView);
            iv_devices_pictru = itemView.findViewById(R.id.my_main_devics_item_iv_devices_pictru);

        }
    }
}
